from collections import Counter


class Solution:
    def lengthOfLongestSubstring(self, s: str) -> int:
        ans = 0
        size = len(s)
        count = Counter()
        left, right = 0, 0
        while left < size:
            while right < size and count[s[right]] <= 0:
                count[s[right]] += 1
                right += 1
            ans = max(ans, right - left)
            count[s[left]] -= 1
            left += 1
        return ans


if __name__ == "__main__":
    print(Solution().lengthOfLongestSubstring(s="abcabcbb"))  # 3
    print(Solution().lengthOfLongestSubstring(s="bbbbb"))  # 1
    print(Solution().lengthOfLongestSubstring(s="pwwkew"))  # 3
    print(Solution().lengthOfLongestSubstring(s=""))  # 0
